<template>
  <div class="about">
    <div class="all-charts">
      <!-- 园区概况 -->
      <div class="section-one">
        <img
          class="img-header"
          src="https://yjy-teach-oss.oss-cn-beijing.aliyuncs.com/smartPark/%E5%A4%A7%E5%B1%8F%E5%88%87%E5%9B%BE/%E5%9B%AD%E5%8C%BA%E6%A6%82%E5%86%B5%402x.png"
          alt=""
        />
        <div class="icons-container">
          <div class="item">
            <div class="icons-item building-icon">
              <span class="number">
                {{ base.buildingTotal }}
              </span>
            </div>
            <span class="title">楼宇总数</span>
            <span class="unity">（栋）</span>
          </div>
          <div class="item">
            <div class="icons-item enterprise-icon">
              <span class="number">
                {{ base.enterpriseTotal }}
              </span>
            </div>
            <span class="title">入驻企业总数</span>
            <span class="unity">（家）</span>
          </div>
          <div class="item">
            <div class="icons-item car-icon">
              <span class="number">
                {{ base.parkingTotal }}
              </span>
            </div>
            <span class="title">车位总数</span>
            <span class="unity">（个）</span>
          </div>
          <div class="item">
            <div class="icons-item rod-icon">
              <span class="number">
                {{ base.chargePoleTotal }}
              </span>
            </div>
            <span class="title">一体杆总数</span>
            <span class="unity">（个）</span>
          </div>
        </div>
      </div>
      <!-- 园区年度收入分析 -->
      <div class="section-two">
        <img
          class="img-header"
          src="https://yjy-teach-oss.oss-cn-beijing.aliyuncs.com/smartPark/%E5%A4%A7%E5%B1%8F%E5%88%87%E5%9B%BE/%E5%9B%AD%E5%8C%BA%E5%B9%B4%E5%BA%A6%E6%94%B6%E5%85%A5%E5%88%86%E6%9E%90%402x.png"
          alt=""
        />
        <div class="bar-chart-titile">
          <span>单位：元</span>
          <div>
            <span class="bar-icon blue-bar-icon"></span>
            <span class="bar-icon red-bar-icon"></span>
            收入情况
          </div>
        </div>
        <div class="bar-chart" ref="barChart" id="barChart"></div>
      </div>
      <div class="section-three">
        <img
          class="img-header"
          src="https://yjy-teach-oss.oss-cn-beijing.aliyuncs.com/smartPark/%E5%A4%A7%E5%B1%8F%E5%88%87%E5%9B%BE/%E5%9B%AD%E5%8C%BA%E4%BA%A7%E4%B8%9A%E5%88%86%E5%B8%83%402x.png"
          alt=""
        />
        <div class="pie-chart" ref="pieChart" id="pieChart"></div>
      </div>
    </div>
     <div class="model-container">
      <LoadComponent :loading="showLoading"></LoadComponent>
    <!-- 准备3D渲染节点 -->
    <canvas class="canvas-3d" ref="ref3d" />
  </div>
  </div>
</template>
<style scoped>
.model-container {
  height: 100%;
  background-color: black;
  width: 100%;
  flex-shrink: 0;
}
</style>
<script setup>
import * as echarts from "echarts";
import { onMounted, ref } from "vue";
import { stainfo } from "../api/index";
import {Application} from "@splinetool/runtime"
import LoadComponent from "./LoadComponent.vue"
const publistPath='https://fe-hmzs.itheima.net'
const showLoading=ref(false);

const ref3d=ref(null)
const init3Dmodel=()=>{
showLoading.value=true;

//实例化解析器实例
let spline=new Application(ref3d.value);
console.log(spline,"spline");
spline.load('https://fe-hmzs.itheima.net/scene.splinecode').then(()=>{
showLoading.value=false
console.log("3D模型加载完毕");
})
}
const base = ref({});
const parkIncome = ref({});
const parkIndustry = ref({});
onMounted(() => {
  getdata();
  init3Dmodel()
});
const getdata = async () => {
  const res = await stainfo();
  console.log(res);
  base.value = res.data.base;
  parkIncome.value = res.data.parkIncome;
  parkIndustry.value = res.data.parkIndustry;
  initchart(parkIncome.value);
  initpiechart(parkIndustry.value);
};
const initpiechart = (b) => {
  const chart = echarts.init(document.getElementById("pieChart"));
  let option = {
    tooltip: {
      trigger: "item",
    },
    legend: {
      top: "5%",
      left: "center",
      textStyle:{
        color:"#fff"
      }
    },
    series: [
      {
  
        type: "pie",
     radius: ['55%', '60%'], // 设置内圈与外圈的半径使其呈现为环形
        center: ['50%', '60%'], // 圆心位置， 用于调整整个图的位置
        avoidLabelOverlap: false,
        label: {
          show: false,
          position: "center",
        },
        emphasis: {
          label: {
            show: false,
            fontSize: 40,
            color:"#fff",
            fontWeight: "bold",
          },
        },
        labelLine: {
          show: false,
        },
        data: b,
      },
    ],
  };
  chart.setOption(option);
};
const initchart = (a) => {
  const chart = echarts.init(document.getElementById("barChart"));
  let option = {
    tooltip: {
      trigger: "axis",
    },
    grid: {
      top: "10px",
      left: "0px",
      right: "0px",
      bottom: "0px",
      containLabel: true,
    },

    xAxis: {
      type: "category",
      data: a.xMonth,
    },
    yAxis: {
      type: "value",
    },
    series: [
      {
        name: "园区收入",
        data: a.yIncome,
        type: "bar",
      },
    ],
  };
  chart.setOption(option);
};
</script>
<style>
.about {
  width: 100%;
  height: 100%;
  background: #000;
}
</style>
<style lang="less">
.section-three {
  flex-basis: 40%;

  .pie-chart {
    position: relative;
    margin: 0 auto;
    padding-bottom: 20px;
    width: 80%;
    height: calc(100% - 40px);
  }
}
.section-two {
  flex-basis: 35%;
  margin-top: 50px;

  .bar-chart {
    width: 100%;
    height: calc(100% - 90px);
  }
}
.all-charts {
  position: absolute;
  top: 0;
  left: 0;
  width: 480px;
  height: 100vh;
  padding: 20px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: linear-gradient(
    to left,
    rgba(0, 6, 15, 0) 0%,
    rgba(0, 6, 15, 0) 20%,
    rgba(0, 0, 0, 0.4) 30%,
    rgba(0, 0, 0, 0.6) 40%,
    rgba(1, 4, 11, 1) 70%,
    #04070d 100%
  );

  .img-header {
    height: 30px;
  }
}
.all-charts .section-one {
  flex-basis: 25%;
  .icons-container {
    display: flex;
    justify-content: space-between;
    padding: 20px 0;

    .item {
      text-align: center;
      display: flex;
      flex-direction: column;
      flex: 1;

      .icons-item {
        height: 80px;
        position: relative;

        .number {
          position: absolute;
          left: 50%;
          transform: translateX(-50%);
          font-size: 18px;
          font-family: FontquanXinYiGuanHeiTi, FontquanXinYiGuanHeiTi-Regular;
          color: #ffffff;
        }
      }

      .building-icon {
        background: url("@/assets/building-icon.png") no-repeat 50% 0 / contain;
      }

      .enterprise-icon {
        background: url("@/assets/enterprise-icon.png") no-repeat 50% 0 /
          contain;
      }

      .rod-icon {
        background: url("@/assets/rod-icon.png") no-repeat 50% 0 / contain;
      }

      .car-icon {
        background: url("@/assets/car-icon.png") no-repeat 50% 0 / contain;
      }

      .title,
      .unity {
        font-size: 14px;
        color: #cdd7e1;
      }

      .title {
        margin-top: 8px;
      }
    }
  }
}
</style>